package com.goldgov.branchCircle.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.goldgov.branchCircle.service.BranchCircle;
import com.goldgov.branchCircle.service.BranchCircleQuery;
import com.goldgov.branchCircle.service.BranchCircleService;
import com.goldgov.kcloud.core.json.JsonQueryObject;
import com.goldgov.meetingstatistics.bean.MeetingOrg;
import com.goldgov.meetingstatistics.bean.MeetingOrgQuery;
import com.goldgov.utils.DateUtil;
import com.goldgov.utils.PropertyUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/** 
 * @ClassName: BranchCircleController 
 * @Description: TODO
 * @author MaN
 * @date 2018年6月19日 
 */

@RestController
@RequestMapping("/workbench/branchCircleStatistics")
@Api("支部圈接口")
public class BranchCircleStatisticsController {

	@Autowired
	private BranchCircleService branchCircleService;
	
	
	
	@GetMapping("/livenessStatistics")
	@ApiOperation(value = "支部圈活跃度统计列表", notes ="")
	@ApiImplicitParams({@ApiImplicitParam(name = "searchDateType", value = "查询类型", paramType = "query"),
		@ApiImplicitParam(name = "searchOrgID", value = "组织id", paramType = "query"),
		@ApiImplicitParam(name = "searchYear", value = "年度", paramType = "query")})
	public JsonQueryObject<BranchCircle> listBranchCircleByAdmin(@ApiIgnore BranchCircleQuery query,HttpServletRequest request){
//		String u=LoginAuthUser.getScopeCodeByFunctionID(AuthorityInfoInit.zbq,request);
//		query.setSearchScopeCode(u);
		query.setPageSize(-1);
		if (!PropertyUtil.objectNotEmpty(query.getSearchYear())) {
			query.setSearchYear(String.valueOf(DateUtil.getYear(new Date())));
		}
		query.setPageSize(-1);
		List<BranchCircle> list=branchCircleService.findLivenessStatistics(query);
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	
	@GetMapping("/findOrgBranchCSList")
	@ApiOperation(value = "支部圈发布数量点击是弹出的统计列表", notes ="")
	@ApiImplicitParams({@ApiImplicitParam(name = "searchType", value = "查询类型", paramType = "query"),
		@ApiImplicitParam(name = "searchParam", value = "时间参数", paramType = "query"),
		@ApiImplicitParam(name = "searchOrganizationName", value = "组织名称", paramType = "query"),
		@ApiImplicitParam(name = "searchOrganizationID", value = "组织id", paramType = "query")})
	public JsonQueryObject<MeetingOrg> findOrgBranchCSList(@ApiIgnore MeetingOrgQuery query,HttpServletRequest request,Model model){
		List<MeetingOrg> list = new ArrayList<>();
		if (PropertyUtil.objectNotEmpty(query.getSearchType()) && PropertyUtil.objectNotEmpty(query.getSearchParam())) {
			list = branchCircleService.findOrgBranchCSList(query);
		}else {
			model.addAttribute("message", "请传入查询类型和时间！");
		}
		query.setResultList(list);
		return new JsonQueryObject<>(query);
	}
	
}
